package de.fhaugsburg.games.boardgames;

import java.util.ArrayList;
import java.util.List;

public class CircularList<T> {

	
	private int current = 0;
	private List<T> list;// = new ArrayList<T>();
	
	
	/**
	 * constructor
	 * @param listSize
	 */
	public CircularList(int listSize) {
		list = new ArrayList<T>(listSize);
	}
	
	
	
	private void incCur() {
		if (++current >= list.size()) {current = 0;}
	}
	
	private void decCur() {
		if (--current <= -1) {current = (list.size()-1);}
	}
	
	/**
	 * Adds a element to CircularList
	 * @param o
	 */
	public T add(T o) {
		list.add(o);
		return o;
	}
	
	/**
	 * Returns next element of CircularList
	 * @return
	 */
	public T next() {
		incCur();
		return list.get(current);
	}
	
	
	/**
	 * Returns current element
	 * @return
	 */
	public T current() {
		return list.get(current);
	}
	
	
	/**
	 * Resets the list counter
	 */
	public void reset() {
		this.current = 0;
	}
	
	/**
	 * Returns last element of CircularList
	 * @return
	 */
	public T prev() {
		decCur();
		return list.get(current);
	}
	
	/**
	 * returns if first element
	 */
	public boolean isOnFirst() {
		if (current == 0) {return true;}
		else {return false;}
	}
	
	/**
	 * Returns whole CircularList
	 * @return
	 */
	public List<T> getAll() {
		return this.list;
	}
	
}
